package union

class Organograma {

	String descricao
	Organizacao organizacao
	
	String toString(){
		"${this.descricao}"
	}
	
	static hasMany = [areasOrganograma:AreasOrganograma, organizacao:Organizacao]
	
	//controle many-to-many
	List areas(){
		return areasOrganograma.collect{it.area}
	}
	
	List addToAreas(Area area){
		AreasOrganograma.link(area, this)
		return areas()
	}
	
	List removeFromAreas(Area area){
		AreasOrganograma.unlink(area, this)
		return areas()
	}
	//controle many-to-many
	
	static constraints = {
		descricao(nullable:true, blank:true)
    }
}
